package homeWork.SOC8.mission_Extra;

import javax.swing.*;
import java.awt.*;

/**
 * 拓展任务
 */
public class ExtraDemo extends JFrame{

    //定义组件
    private JPanel jp_1,jp_2;
    private JLabel tips;
    private JTextField number_input;
    private JButton btn_start,btn_restart,btn_exit;

    public ExtraDemo(){
        //初始化组件
        initViews();

        //将组件放入对应面板中
        IntoJPanel();

        //将面板放入窗体中
        IntoJFrame();

    }

    private void IntoJFrame() {
        //将面板放入窗体中
        add(jp_1);
        add(jp_2);

        //初始化窗体
        setTitle("猜字游戏!");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLayout(new FlowLayout(FlowLayout.CENTER));
        setResizable(true);
        setSize(400,150);
        setVisible(true);
    }

    private void IntoJPanel() {
        jp_1.add(tips);
        jp_1.add(number_input);
        jp_1.setBackground(Color.GREEN);
        jp_2.add(btn_start);
        jp_2.add(btn_restart);
        jp_2.add(btn_exit);
        jp_2.setBackground(Color.BLUE);
    }

    private void initViews() {
        jp_1 = new JPanel();
        jp_2 = new JPanel();
        tips = new JLabel("请输入要猜测的数字:");
        number_input = new JTextField("输入的数字",10);
        btn_start = new JButton("开始猜测");
        btn_restart = new JButton("重新猜字");
        btn_exit = new JButton("退出猜字");
    }


    public static void main(String[] args) {
        new ExtraDemo();
    }
}
